-- NewBagView

local NewPlayerPanel = app:getClass("NewPlayerPanel")
local NewBagMultPanel = import(".NewBagMultPanel")

local NewBagPanel = app:getClass("NewBagPanel")
local NewRarePanel = app:getClass("NewRarePanel")
local NewClothesPanel = app:getClass("NewClothesPanel")
local NewTitlePanel = app:getClass("NewTitlePanel")
local NewRenownPanel = app:getClass("NewRenownPanel")

local newFloatTipsView = require("app.newFloatTips.newFloatTipsView")

local NewBagUpView = import(".NewBagUpView")
local NewEquipStrengthenView = import(".NewEquipStrengthenView")
local NewRareInfoView = import(".NewRareInfoView")

local panelPlayerLocalZOrderTemp = nil -- playerPanel 初始 LocalZOrder 缓存
local rightBtnPanelInitPosY = {}

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

local CONSTANT_LEFT_SAFE_WIDTH = 5

ClassRef.VIEW_ROOT_RES = Res.NewBagUi

local panelIndexTable = {
	"bag",
	"rare",
	"clothes",
	"title",
	"renown"
}


function ClassRef:init()
	self._panelTable = {} -- 右侧panel表

	self._renderTemp = nil -- 当前tips触发render缓存
	self._renderPosTemp = nil -- 当前tips触发render Pos缓存

	-- left equip
	self._playerPanel = NewPlayerPanel.create()
	self._playerPanel:setPosition(self._ui["Panel/player"]:getPosition())
	self._ui["Panel"]:addChild(self._playerPanel)
	self._ui["Panel/player"]:setVisible(false)


	panelPlayerLocalZOrderTemp = self._playerPanel:getLocalZOrder()
	self._playerPanel:setVisible(true)
	self._playerPanel:setClickHandler(function(op, render) -- 人物身上的操作
			local renderData = render:getData()
			if renderData then
				if "PlayerPanel_showEquipTip" == op then -- 选中装备
					executeFunc(self._onOperate, "PlayerPanel_showEquipTip", render)
				elseif "PlayerPanel_selectedOtherEquipWhenStrengthShown" == op then -- 在装备强化UI显示时选中其他装备
					assert( self._equipStrengthenPanel, " ------>>>> 在装备强化UI显示时选中其他装备,但是panel却不存在了 " )

					local curData = self._equipStrengthenPanel:getData()
					if curData.uid == renderData.uid then
						return
					else
						self._equipStrengthenPanel:setData( renderData )
					end
				elseif "PlayerPanel_selectedClothes" == op then -- 选中时装、需要在衣橱中定位到
					executeFunc(self._onOperate, "PlayerPanel_selectedClothes", render)
				end
			end
		end)
	
	self._playerPanel:registerOnOperate(function(op, ...) -- 右侧所有panel的操作都在此处处理
		executeFunc(self._onOperate, op, ...)		
	end)
	-- bagUp panel
	self._bagUpPanel = nil

	-- equip strengthen panel
	self._equipStrengthenPanel = nil

	-- right bag
	self._ui["Panel/Panel_right/Button_close"]:addClickEventListener(function()
		executeFunc(self._onCloseView)
	end)

	self._curRightPanelIndex = 1 -- 默认选中第一项、即背包
	for _,btnTemp in ipairs( self._ui["Panel/Panel_right/Panel_tab"]:getChildren() ) do
		table.insert( rightBtnPanelInitPosY, btnTemp:getPositionY() )

		btnTemp:getChildByName( "dot" ):setVisible( false ) -- 先不处理dot

		btnTemp:addClickEventListener(function( sender )
			local btnName = sender:getName()
			local selectedIndex = string.sub( btnName, string.len(btnName), string.len(btnName) )

			self._curRightPanelIndex = tonumber( selectedIndex )
			self:switchPanel()
		end)
	end

	self._curRrender = nil -- 当前背包中选中的物品

	self._leftTip = nil
	self._rightTip = nil
	self._floatTipBg = nil

	self._opType = 1
	self._multPanel = nil

	self._qqBtn1 = self._ui["Panel_1/btn_qq_1"]
    self._qqBtn2 = self._ui["Panel_1/btn_qq_2"]
	self._wxBtn = self._ui["Panel_1/btn_wx_1"]
	self._qqBtn1:addClickEventListener(handler(self, self._onClickQQGameWakeUp))
    self._qqBtn2:addClickEventListener(handler(self, self._onClickQQVip))
	self._wxBtn:addClickEventListener(handler(self, self._onClickWXGameWakeUp))
	
	self._realNameTag = self._ui["Panel_1/img_smrz"]

	self:refreshOPBtnVisibleByFuncOpen()
	self:refreshMsdk()
end


-- 检查是否触发了引导
function ClassRef:checkGuide()
    local funcId = Constant.FUNC_TYPE_PACK
    local params = {
        scene = funcId,
        sceneSelf = self,
        getFunc = self.getGuideNodeFunc,
        nextFunc = self.checkGuide
    }
    EM:notify("checkGuide", params)
end

-- 获取引导node
function ClassRef:getGuideNodeFunc(id)
    if id == 113 then
        -- 强化提示1，选中武器
        local render = self._playerPanel:getEquipRender( 1 )
        local renderData = render:getData()
        if renderData then
        	return render
    	end
        return
    elseif id == 114 then
        -- 强化提示2，点击tips上的强化按钮
        if self._rightTip then
        	return self._rightTip:getBtnByName( "Button_strengthen" )
        end
        return
    elseif id == 115 then
        -- 强化提示3，查看强化界面的道具消耗
		if self._equipStrengthenPanel then
			return self._equipStrengthenPanel._neededIcon
		end
		return
    elseif id == 116 then
        -- 强化提示4，点击强化按钮
		if self._equipStrengthenPanel then
			return self._equipStrengthenPanel:findChild( "Panel/Panel_up/Button_s" )
		end
		return
    elseif id == 117 then
        -- 强化提示5，点击强化后属性
		if self._equipStrengthenPanel then
			return self._equipStrengthenPanel:findChild( "Panel/Panel_mid/data_2/Panel" )
		end
		return
    end
end

function ClassRef:show( selectedIndex )
	self.super.show(self)
	self:updatePlayerEquip()
	self:switchPanel( selectedIndex )

	self:checkGuide()
end

function ClassRef:onSwitchPanel(cb)
	self._onSwitchPanel = cb
end
function ClassRef:onSwitchOpType(cb)
	self._onSwitchOpType = cb
end

-- 原来背包的容器，现在移动到bagpanel中
function ClassRef:getScrollView()
	return self:getRightPanelByIndex(1):getScrollView()
end

function ClassRef:isClothesPanel()
    return 3 == self._curRightPanelIndex
end


function ClassRef:switchPanel( selectedIndex )
	if selectedIndex then
		self._curRightPanelIndex = selectedIndex
	end

	for i = 1 , 5 do
		local bagBtn = self._ui["Panel/Panel_right/Panel_tab/selected_btn_"..i]
		bagBtn:setTouchEnabled( true )
		bagBtn:setBright( true )
		bagBtn:getChildByName( "name_1" ):setVisible( true )
		bagBtn:getChildByName( "name_2" ):setVisible( false )

		self._ui["Panel/Panel_right/".. panelIndexTable[i] ]:setVisible( false )
	end
	local bagBtn = self._ui["Panel/Panel_right/Panel_tab/selected_btn_"..self._curRightPanelIndex]
	bagBtn:setTouchEnabled( false )
	bagBtn:setBright( false )
	bagBtn:getChildByName( "name_1" ):setVisible( false )
	bagBtn:getChildByName( "name_2" ):setVisible( true )

	self._ui["Panel/Panel_right/".. panelIndexTable[self._curRightPanelIndex] ]:setVisible( true )

	if self:isClothesPanel() then
		self._playerPanel:setClothesVisible( true )
		self._playerPanel:packupStrengthPanel()
		self._playerPanel:setAttrAndStrengthShown( false )
	else
		self._playerPanel:setClothesVisible( false )
		self._playerPanel:setAttrAndStrengthShown( true )
	end
	executeFunc(self._onSwitchPanel, self._curRightPanelIndex)
end

function ClassRef:getRightPanelByIndex( rightPanelIndex )
	local curPanelTemp = self._panelTable[rightPanelIndex]
	if not curPanelTemp then
		local curNode = self._ui["Panel/Panel_right/".. panelIndexTable[rightPanelIndex] ]
		if 1 == rightPanelIndex then -- 背包
			curPanelTemp = NewBagPanel.create(curNode)
		elseif 2 == rightPanelIndex then -- 宝物
			curPanelTemp = NewRarePanel.create(curNode)
		elseif 3 == rightPanelIndex then -- 时装
			curPanelTemp = NewClothesPanel.create(curNode)
		elseif 4 == rightPanelIndex then -- 称号
			curPanelTemp = NewTitlePanel.create(curNode)
		elseif 5 == rightPanelIndex then -- 声望
			curPanelTemp = NewRenownPanel.create(curNode)
		end
		self._panelTable[rightPanelIndex] = curPanelTemp
		curPanelTemp:registerOnOperate(function(op, ...) -- 右侧所有panel的操作都在此处处理
					if "BagPanel_decompose" == op then -- 背包批量分解
						-- self:switchOpType(3)
						if self._multPanel then
							if self._multPanel:canOpen() then
								self:switchOpType(3)
							elseif self._multPanel:canClose() then
								self:switchOpType(1)
							end
						else
							self:switchOpType(3)
						end
					elseif "BagPanel_scrolling" == op then -- 背包 scrollView 滚动中
						self:clearTips()
					elseif "BagPanel_bounceStart" == op then -- 背包 scrollView 回弹开始
						self._bounceing = true
					elseif "BagPanel_bounceStop" == op then -- 背包 scrollView 回弹结束
						self._bounceing = false
					else
						executeFunc(self._onOperate, op, ...)
					end
				end)
	end

	return curPanelTemp
end


-- 操作类型：普通点击、批量分解
function ClassRef:switchOpType(type)
	self:setCurRender(nil)

	self._opType = type
	if self._opType > 1 then
		self:_showMultPanel()
	else
		self:_hideMultPanel()
	end
	executeFunc(self._onSwitchOpType, self._opType)
end

function ClassRef:getMultSV()
	if self._multPanel then
		return self._multPanel:getScrollView()
	end
end

function ClassRef:getMulPanel()
	return self._multPanel
end


function ClassRef:isMultSVShown()
	if self._multPanel and self._multPanel:isOpen() then
		return true
	end
	return false
end

-- 刷新分解所获得的数量
function ClassRef:refreshDecomposeGotNum( breakDropList )
	if self._multPanel then
		return self._multPanel:refreshDecomposeGotNum( breakDropList )
	end
end
function ClassRef:_showMultPanel()
	if not self._multPanel then
		self._multPanel = NewBagMultPanel.create()
		self._ui["Panel"]:addChild( self._multPanel, 200 )
		local pos = cc.p( self._playerPanel:getPosition() )
		local size = self._playerPanel:getChildByName( "Panel" ):getContentSize()
		self._multPanel:setPosition( cc.p( pos.x + size.width/2, pos.y + size.height/2 ) )
		self._multPanel:onOperate(function(op, ...)
			if op == "close" then
				self:switchOpType(1)
			elseif op == "closeAnimationEnd" then
				self:_showPanelWhenMultPanelClose()
			else
				executeFunc(self._onOperate, op, ...)
			end
		end)
	end
	if not self._multPanel:canOpen() then
		return
	end
	-- todo add show/hide action
	self._multPanel:setVisible(true)
	
	self._multPanel:playOpen()
	self:getRightPanelByIndex(1):refreshBreakBtnTouchEnabled( false )

	self._multPanel:setData(self._opType)

	for i = 2, 5 do
		self._ui["Panel/Panel_right/Panel_tab/selected_btn_"..i]:setVisible( false )
	end

	self._playerPanel:setVisible(false)
end


function ClassRef:_hideMultPanel()
	if not self._multPanel then return end
	if not self._multPanel:canClose() then
		return
	end
	self._multPanel:playClose()
	-- self._multPanel:setVisible(false)
	
end

function ClassRef:_showPanelWhenMultPanelClose()
	self:getRightPanelByIndex(1):refreshBreakBtnTouchEnabled(true)
	self._playerPanel:setVisible(true)

	for i = 2, 5 do
		self._ui['Panel/Panel_right/Panel_tab/selected_btn_' .. i]:setVisible(true)
	end
	self:refreshOPBtnVisibleByFuncOpen()
end

-- 根据功能开放条件刷新右侧按钮可见性
function ClassRef:refreshOPBtnVisibleByFuncOpen()
	if UIHandler:isFunctionOpen(Constant.FUNC_TYPE_PACK_TREASURE) then
		self._ui["Panel/Panel_right/Panel_tab/selected_btn_2"]:setVisible( false ) -- 宝物界面不要了，修改到了日常界面中
	else
		self._ui["Panel/Panel_right/Panel_tab/selected_btn_2"]:setVisible( false )
	end
	if UIHandler:isFunctionOpen(Constant.FUNC_TYPE_PACK_WARDROBE) then
		self._ui["Panel/Panel_right/Panel_tab/selected_btn_3"]:setVisible( true )
	else
		self._ui["Panel/Panel_right/Panel_tab/selected_btn_3"]:setVisible( false )
	end
	if UIHandler:isFunctionOpen(Constant.FUNC_TYPE_PACK_TITLE) then
		self._ui["Panel/Panel_right/Panel_tab/selected_btn_4"]:setVisible( true )
	else
		self._ui["Panel/Panel_right/Panel_tab/selected_btn_4"]:setVisible( false )
	end
	if UIHandler:isFunctionOpen(Constant.FUNC_TYPE_PACK_PRESTIGE) then
		self._ui["Panel/Panel_right/Panel_tab/selected_btn_5"]:setVisible( true )
	else
		self._ui["Panel/Panel_right/Panel_tab/selected_btn_5"]:setVisible( false )
	end

    -- 以下：动态调整posY
    local visibleBtnNum = 1 -- 可见按钮个数、默认为1（背包一定可见）
    for i = 2, 5 do
    	if self._ui["Panel/Panel_right/Panel_tab/selected_btn_" .. i]:isVisible() then
    		visibleBtnNum = visibleBtnNum + 1
    		self._ui["Panel/Panel_right/Panel_tab/selected_btn_" .. i]:setPositionY( rightBtnPanelInitPosY[visibleBtnNum] )
    	end
    end
end

function ClassRef:setCurRender(render) -- 设置背包中物品的选中态
	if self._curRrender then
		self._curRrender:setSelected(false)
	end
	self._curRrender = render

	self._playerPanel:unselectedCurRender() -- 取消选中人物身上的装备
end

function ClassRef:selectedClothesRenderByPos( clothesPos )
	self._playerPanel:selectedClothesRenderByPos( clothesPos )
end
 -- clothesPanaelIdx-衣橱当前选中索引
function ClassRef:setCurClothesRenderData( clothesPanelIdx, fashionId)
	self._playerPanel:unselectedCurClothesRender() -- 取消选中人物身上的时装

	self:getRightPanelByIndex(3):setCurClothesRenderData( clothesPanelIdx, fashionId )

	self._playerPanel:setAttrAndStrengthShown( not self:isClothesPanel() )
end
function ClassRef:getCurClothesRenderDataByIdx( idx )
	return self:getRightPanelByIndex(3):getCurClothesRenderDataByIdx( idx )
end

function ClassRef:getCurClothesRenderData( idx )
    return self:getRightPanelByIndex(3):getCurClothesRenderData()
end



function ClassRef:showBagUpView()
	self._ui["Panel/Panel_right/Panel_tab"]:setVisible( false )
end

function ClassRef:hideBagUpView()
	self._ui["Panel/Panel_right/Panel_tab"]:setVisible( true )
end

-- 显示装备强化UI
function ClassRef:showEquipStrengthenUI( equipData )
	local equipDataTemp = equipData
	-- 如果刷新的时候强化panel处于显示状态
	local curSelectedEquip = nil
	if not cc.isDead(self._equipStrengthenPanel) and self._equipStrengthenPanel:isVisible() and self._playerPanel then
		curSelectedEquip = self._playerPanel:getCurSelectedEquip()
	end
	if curSelectedEquip then -- 当前存在选中的装备？
		local curSelectedEquipData = curSelectedEquip:getData()
		if curSelectedEquipData.uid ~= equipData.uid then -- 非同一件装备？
			equipDataTemp = curSelectedEquipData
		end
	end

	if self._equipStrengthenPanel then

		self._ui["Panel/Panel_right/Panel_bg"]:setVisible( false )
		self._ui["Panel/Panel_right/Panel_tab"]:setVisible( false )
		self._ui["Panel/Panel_right/Button_close"]:setVisible( false )
		self._panelTable[self._curRightPanelIndex]:setVisible( false )

		self._equipStrengthenPanel:setData( equipDataTemp )
		self._playerPanel:setEquipGridStrengthPanelVisble( true )
	else
		self._equipStrengthenPanel = NewEquipStrengthenView.create()

		self._ui["Panel/Panel_right/Panel_bg"]:setVisible( false )
		self._ui["Panel/Panel_right/Panel_tab"]:setVisible( false )
		self._ui["Panel/Panel_right/Button_close"]:setVisible( false )
		self._panelTable[self._curRightPanelIndex]:setVisible( false )

		self._equipStrengthenPanel:setData( equipDataTemp )
		self._playerPanel:setEquipGridStrengthPanelVisble( true )

		self._equipStrengthenPanel:registerOnOperate(function(op, ...) -- 装备强化panel的处理
						if "equipStrengthen_closePanel" == op then -- 主动关闭强化Ui
							self._ui["Panel/Panel_right"]:setLocalZOrder( panelPlayerLocalZOrderTemp )
							self._ui["Panel/player"]:setLocalZOrder( panelPlayerLocalZOrderTemp + 1 )

							if self._equipStrengthenPanel then
								self._equipStrengthenPanel:removeFromParent()
								self._equipStrengthenPanel = nil
								self._playerPanel:setEquipGridStrengthPanelVisble( false )

								self._ui["Panel/Panel_right/Panel_bg"]:setVisible( true )
								self._ui["Panel/Panel_right/Panel_tab"]:setVisible( true )
								self._ui["Panel/Panel_right/Button_close"]:setVisible( true )
								self._panelTable[self._curRightPanelIndex]:setVisible( true )
							end
						else
							executeFunc(self._onOperate, op, ...)
						end
					end)
		self._ui["Panel/Panel_right"]:addChild( self._equipStrengthenPanel )
		self._equipStrengthenPanel:setPositionX( - ( self._ui["Panel/Panel_right"]:getPositionX() - self._ui["Panel/Panel_right"]:getContentSize().width ) )

		-- 提高强化 Panel_right 的 Zorder 以响应点击左侧空白区关闭
		self._ui["Panel/player"]:setLocalZOrder( panelPlayerLocalZOrderTemp )
		self._ui["Panel/Panel_right"]:setLocalZOrder( panelPlayerLocalZOrderTemp + 1 )

		-- 点击空白区域关闭
		local nodeList = { self._equipStrengthenPanel:getChildByName( "Panel" ):getChildByName( "Panel_bg" ) }
		for i = 1, 12 do
			table.insert( nodeList, self._playerPanel:getChildByName( "Panel" ):getChildByName( "Panel_equip" ):getChildByName( "equip_"..i ) )
		end
		display.nodeListRemoveForNotHit(nodeList, function()
			self._ui["Panel/Panel_right"]:setLocalZOrder( panelPlayerLocalZOrderTemp )
			self._ui["Panel/player"]:setLocalZOrder( panelPlayerLocalZOrderTemp + 1 )

			if self._equipStrengthenPanel then
				self._equipStrengthenPanel:removeFromParent()
				self._equipStrengthenPanel = nil
				self._playerPanel:setEquipGridStrengthPanelVisble( false )

				self._ui["Panel/Panel_right/Panel_bg"]:setVisible( true )
				self._ui["Panel/Panel_right/Panel_tab"]:setVisible( true )
				self._ui["Panel/Panel_right/Button_close"]:setVisible( true )
				self._panelTable[self._curRightPanelIndex]:setVisible( true )
			end
		end)
	end

	self:checkGuide()
end

function ClassRef:refreshStrengthNeedItem(tid)
	if self._equipStrengthenPanel and self._equipStrengthenPanel:isVisible() then
		self._equipStrengthenPanel:updateItem(tid)
	end
end

-- 播放强化成功动画
function ClassRef:playStrengthSuccessAmi()
	if self._equipStrengthenPanel then
		self._equipStrengthenPanel:playStrengthSuccessAmi()
	end
end

-- 播放强化失败动画
function ClassRef:playStrengthFailAmi()
	if self._equipStrengthenPanel then
		self._equipStrengthenPanel:playStrengthFailAmi()
	end
end

function ClassRef:clearTips(ignoreSelect)
	if self._rightTip then
		self._rightTip:setVisible( false )
	end
	if self._leftTip then
		self._leftTip:setVisible( false )
	end
	if self._clipNode then
		self._clipNode:setVisible(false)
	end

	ignoreSelect = ignoreSelect or false
	if not ignoreSelect then
		self:setCurRender(nil)
	end
end
-- 显示tips
function ClassRef:showTips(render, leftParams, rightParams)
	if self._bounceing then
		return
	end
	if self._renderTemp then
		self:clearTips(true)
	end
	self._renderTemp = render

	local closeCallBack = function()
		self:clearTips()
	end

	local boundingBoxTemp = nil
	if render then
		boundingBoxTemp = render:getBoundingBox()
		local worldPosTemp = render:getParent():convertToWorldSpace( cc.p( boundingBoxTemp.x, boundingBoxTemp.y ) )
		boundingBoxTemp.x = worldPosTemp.x
		boundingBoxTemp.y = worldPosTemp.y
	end

	if leftParams then
		leftParams.notAutoHide = true
		leftParams.closeCallBack = closeCallBack

		if not self._leftTip then
			self._leftTip = newFloatTipsView.new( leftParams )
			self:addChild(self._leftTip, 200)
			display.adjustNodePos( boundingBoxTemp, self._leftTip.mUINode, 10 )
		else
			self._leftTip:refreshContent( leftParams )
			display.adjustNodePos( boundingBoxTemp, self._leftTip.mUINode, 10 )
		end
		self._leftTip:setVisible( true )
	end
	if rightParams then
		rightParams.notAutoHide = true
		rightParams.closeCallBack = closeCallBack
		if not self._rightTip then
			self._rightTip = newFloatTipsView.new( rightParams )
			self:addChild(self._rightTip,200)
			display.adjustNodePos( boundingBoxTemp, self._rightTip.mUINode, 10 )
		else
			self._rightTip:refreshContent( rightParams )
			display.adjustNodePos( boundingBoxTemp, self._rightTip.mUINode, 10 )
		end
		self._rightTip:setVisible( true )

		if self._leftTip and self._leftTip:isVisible() then -- 出现比较的情况
			local leftTipPosX = self._leftTip.mUINode:getPositionX()
			local leftTipSize = self._leftTip.mUINode:getContentSize()
			local leftTipHeight = leftTipSize.height

			local rightTipsPosX = self._rightTip.mUINode:getPositionX()
			local rightTipsPosY = self._rightTip.mUINode:getPositionY()
			local rightTipsSize = self._rightTip.mUINode:getContentSize()
			local rightTipsWidth = rightTipsSize.width
			local rightTipsHeight = rightTipsSize.height

			local leftPosX = leftTipPosX - rightTipsWidth
			local offsetX = 0
			if (CONSTANT_LEFT_SAFE_WIDTH + display.safe_x) > leftPosX then -- 左越界？
				offsetX = CONSTANT_LEFT_SAFE_WIDTH - leftPosX + display.safe_x
				leftPosX = CONSTANT_LEFT_SAFE_WIDTH + display.safe_x
			end
			self._leftTip.mUINode:setPositionX(leftPosX)
			if rightTipsHeight > leftTipHeight then
				self._leftTip.mUINode:setPositionY(rightTipsPosY + rightTipsHeight - leftTipHeight)
			end
			self._rightTip.mUINode:setPositionX(rightTipsPosX + offsetX)
		end
	end

	-- 自动隐藏逻辑
	local nodeList = {}
	if self._leftTip and self._leftTip:isVisible() then -- 左侧tips可见
		table.insert( nodeList, self._leftTip.bg:getChildByName("bg") )
	end
	if self._rightTip and self._rightTip:isVisible() then -- 右侧tips可见
		table.insert( nodeList, self._rightTip.bg:getChildByName("bg") )
	end
	self._handlerTemp = display.nodeListRemoveForNotHit(nodeList, function()
		cc.Director:getInstance():getEventDispatcher():removeEventListener( self._handlerTemp )
		self._handlerTemp = nil

		if self._leftTip and self._leftTip:isVisible() then -- 左侧tips可见
			self._leftTip._fromBtnTips:hide()
			self._leftTip:setVisible(false)
		end
		if self._rightTip and self._rightTip:isVisible() then -- 左侧tips可见
			self._rightTip._fromBtnTips:hide()
			self._rightTip:setVisible(false)
		end
		self:clearTips()
	end)

	if not self._floatTipBg then -- 创建tipsBg
		local floatTipBg = display.newColorLayer(cc.c4b(0,0,0,255*0.45))
		local clipNode = cc.ClippingNode:create()
		self._stencilSprite = display.newScale9Sprite("public/public_black.png",0, 0, cc.size(100, 100))
		self._stencilSprite:setAnchorPoint(0, 0)
		self._clipNode = clipNode
		clipNode:addChild(floatTipBg)
		clipNode:setStencil(self._stencilSprite)
		clipNode:setAlphaThreshold(0)
		clipNode:setInverted(true)
		self:addChild(clipNode,199)
	end
	
	if ( self._leftTip and self._leftTip:isVisible() ) or ( self._rightTip and self._rightTip:isVisible() ) then -- 有任一tips显示状态
		self._clipNode:setVisible( true )
		
		if boundingBoxTemp then
			self._stencilSprite:setPosition(boundingBoxTemp.x, boundingBoxTemp.y)
			self._stencilSprite:setContentSize(boundingBoxTemp.width, boundingBoxTemp.height)
			-- self._drawNode:drawSolidRect(cc.p(boundingBoxTemp.x, boundingBoxTemp.y), 
			-- 	cc.p(boundingBoxTemp.x + boundingBoxTemp.width, boundingBoxTemp.y + boundingBoxTemp.height), cc.c4f(1, 0, 0, 1))
		end
	else
		self._clipNode:setVisible( false )
	end
	-- 只在装备栏主武器格子tips的时候检测引导
	if render and iskindof(render, "NewEquipRender") then
		local equip = render:getData()
		if equip and equip:isMainWeapon() then
			self:checkGuide()
		end
	end
end

-- 显示宝物详情
function ClassRef:showRareInfo( dataTemp )
	assert( 2 == self._curRightPanelIndex, " -------------->>>>>>>> 显示宝物详情时不处于宝物panel" )

	local pos = self._ui["Panel/Panel_right"]:convertToNodeSpace( dataTemp.pos )
	if self._rareInfoPanel then
		self._rareInfoPanel:setData( dataTemp.data )

		local rareInfoPanelHeight = self._rareInfoPanel:returnContentHeight()
		pos.y = pos.y - rareInfoPanelHeight
		if pos.y < 0 then
			pos.y = 0
		end
		self._rareInfoPanel:setPosition( pos )
	else
		self._rareInfoPanel = NewRareInfoView.create()
		self._rareInfoPanel:setQuickJumpEnable(true)
		self._rareInfoPanel:setData( dataTemp.data )

		self._ui["Panel/Panel_right"]:addChild( self._rareInfoPanel )

		local rareInfoPanelHeight = self._rareInfoPanel:returnContentHeight()
		pos.y = pos.y - rareInfoPanelHeight
		if pos.y < 0 then
			pos.y = 0
		end
		self._rareInfoPanel:setPosition( pos )

		-- 提高强化 Panel_right 的 Zorder 以响应点击左侧空白区关闭
		self._ui["Panel/player"]:setLocalZOrder( panelPlayerLocalZOrderTemp )
		self._ui["Panel/Panel_right"]:setLocalZOrder( panelPlayerLocalZOrderTemp + 1 )

		-- 点击空白区域关闭
		display.nodeRemoveForNotHit(self._rareInfoPanel:getChildByName( "Panel" ), handler(self, self._onCloseRareTips))
		self._rareInfoPanel:onOperate(function(op)
			if op == "jumpto" then
				self:_onCloseRareTips()
			end
		end)
	end
end

function ClassRef:_onCloseRareTips()
	self._ui["Panel/Panel_right"]:setLocalZOrder( panelPlayerLocalZOrderTemp )
	self._ui["Panel/player"]:setLocalZOrder( panelPlayerLocalZOrderTemp + 1 )
	if self._rareInfoPanel then
		self._rareInfoPanel:removeFromParent()
		self._rareInfoPanel = nil
	end
end

-- 刷新侧边按钮红点提示
function ClassRef:updateTabBtnRedPoint( idx, shown)
	self._ui["Panel/Panel_right/Panel_tab/selected_btn_"..idx]:getChildByName( "dot" ):setVisible( shown )
end


-- 刷新背包信息
function ClassRef:updateBagInfo(bagInfo, curNum, maxNum)
	self:getRightPanelByIndex(1):updateBagInfo( bagInfo, curNum, maxNum )
end
-- 背包出售按钮状态
function ClassRef:refreshSellBtn(b)
end
-- 获取身上某个location对应的装备
function ClassRef:getEquipRender(pos)
	return self._playerPanel:getEquipRender(pos)
end

-- 刷新装备
function ClassRef:updatePlayerAllEquip()
	self._playerPanel:refreshEquips( UD.equips )
	self:getRightPanelByIndex(3):resetPreviewData(nil)
end

function ClassRef:updatePlayerAllEquipGrids(lvGrids)
	self._playerPanel:refreshEquipGrids(lvGrids)
	--self:getRightPanelByIndex(3):resetPreviewData(nil)
end

-- 更新装备、附带更新时装
function ClassRef:updatePlayerEquip(pos, equip, op)
	if pos then
		self._playerPanel:refreshEquipByPos(pos, equip, op)

		if self._panelTable[3] then -- 如果当前衣橱衣橱初始化过
			self:getRightPanelByIndex( 3 ):refreshPanelEquip()
		end

		-- 穿上主武器需要检测引导
		if op == "insert" and equip:isMainWeapon() then
			self:checkGuide()
		end
	else
		self._playerPanel:setData(nil)
	end
	self:getRightPanelByIndex(3):resetPreviewData(pos)
end
-- 更新全身时装
function ClassRef:updatePlayerClothes( )
    --格子里的时装ICON更新
	self._playerPanel:refreshClothes()
end

--打开界面默认选中可以强化的一件装备
function ClassRef:setDefaultSelectEquipOnStrength()
	local equipData = self._playerPanel:setDefaultSelectEquipGrid()
	if equipData then
		self:showEquipStrengthenUI(equipData)
	end
end

--在幻化和取消幻化后调用
function ClassRef:updatePlayerClothesByPos(equipGrid, preFashionId, hasAvatarChange, hasHiddenChange)
    self._playerPanel:updateFashionByPos(equipGrid, preFashionId, hasAvatarChange, hasHiddenChange)
	--将预览取消
	self:getRightPanelByIndex(3):resetPreviewData(equipGrid:getLocation())
end

-- 预览时装
function ClassRef:previewClothes( data )
	self._playerPanel:previewClothes( data )
	self._playerPanel:setAttrAndStrengthShown( not self:isClothesPanel() )
end

-- 更新属性
function ClassRef:updateProp(attrList)
	self._playerPanel:refreshProp(attrList)
end
-- 更新强化大师
function ClassRef:updateRecastMaster(curMasterList, nextMasterList)
	self._playerPanel:updateRecastMaster(curMasterList, nextMasterList)
end
-- 更新强化信息
function ClassRef:updateStrengthenInfo()
	self._playerPanel:refreshStrengthenInfo()
end
-- 更新战力
function ClassRef:updateCombatPower()
	self._playerPanel:refreshCombatPower()
end
-- 更新名字
function ClassRef:updatePlayerName( newName )
	self._playerPanel:refreshPlayerName( newName )
end
-- 更新货币1
function ClassRef:updateGold(num)
	self._playerPanel:refreshGold(num)
end
-- 更新货币2
function ClassRef:updateMagicDust(num)
	self._playerPanel:refreshMagicDust(num)
end
-- 更新货币3
function ClassRef:updateMagicCrystal(num)
	self._playerPanel:refreshMagicCrystal(num)
end

function ClassRef:remove()
	for _,panelTemp in pairs( self._panelTable ) do
		panelTemp:remove()
	end
	if self._multPanel then self._multPanel:remove() end
end

function ClassRef:refreshMsdk()
	local height = self._ui["Panel_1"]:getContentSize().height
	local isRealName = app.channelAPI:checkIsRealName()
	self._realNameTag:setVisible(isRealName)
	self._realNameTag:setPositionY(height)
	if isRealName then
		height = height - self._realNameTag:getContentSize().height -4
	end

	local msdkData = UD.msdkData
	local platform = app.channelAPI:getWGPlatform()
	if msdkData:isEnableShowQQGameCenterView() then
		--常显
		if true then  --msdkData:isMyWakeUpFromQQGame() then
			self._qqBtn1:setVisible(true)
			self._qqBtn1:setPositionY(height)
			height = height - self._qqBtn1:getContentSize().height
		else
			self._qqBtn1:setVisible(false)
		end
		if true then --msdkData:isVip() then
			self._qqBtn2:setVisible(true)
			self._qqBtn2:setPositionY(height)
		else
			self._qqBtn2:setVisible(false)
		end

		local vip = msdkData:getVip()
		if vip == Enums.MSDK_QQ_VIP.VIP_NONE then
			self._qqBtn2:loadTexture(Res.BuyQQVipIcon, 1)
		elseif vip == Enums.MSDK_QQ_VIP.VIP_NORMAL then
			self._qqBtn2:loadTexture(Res.BuyQQSuperVipIcon, 1)
		elseif vip == Enums.MSDK_QQ_VIP.VIP_SUPER then
			self._qqBtn2:loadTexture(Res.AlreadyBuySuperVipIcon, 1)
		else
			self._qqBtn2:loadTexture(Res.BuyQQVipIcon, 1)
		end
	elseif msdkData:isEnableShowWXGameCenterView() then
		self._qqBtn1:setVisible(false)
		self._qqBtn2:setVisible(false)
		self._wxBtn:setVisible(true)
		self._wxBtn:setPositionY(height)
	else
		self._qqBtn1:setVisible(false)
		self._qqBtn2:setVisible(false)
		self._wxBtn:setVisible(false)
	end
end


function ClassRef:_onClickQQVip()
	UD.msdkData:qqVipClick()
end

function ClassRef:_onClickQQGameWakeUp()
	UD.msdkData:qqGameWakeUpClick()
end

function ClassRef:_onClickWXGameWakeUp()
	UD.msdkData:wxGameWakeUpClick()
end

function ClassRef:refreshRedPoint()
	self:refreshTabBtnRedPoint()
	self:refreshPlayerRedPoint()
	self:refreshClothesRedPoint()

	-- 宝物界面已经废弃
	-- local rarePanel = self._panelTable[2]
	-- if rarePanel then
	-- 	rarePanel:refreshRedPoint()
	-- end
end

function ClassRef:refreshTabBtnRedPoint()
	self:updateTabBtnRedPoint( 1, UD.redPoint:getStateByKey(RedPointConstant.Bag_NewItem) )
	-- 宝物new标记
	self:updateTabBtnRedPoint( 2, UD.redPoint:getStateByKey(Constant.FUNC_TYPE_PACK_TREASURE) )
	-- 有新获得时装
	self:updateTabBtnRedPoint( 3, UD.redPoint:getStateByKey(Constant.FUNC_TYPE_PACK_WARDROBE) )
	-- 有新获得称号
	self:updateTabBtnRedPoint( 4, UD.redPoint:getStateByKey(Constant.FUNC_TYPE_PACK_TITLE) )
	-- 有新改变的声望
	self:updateTabBtnRedPoint( 5, UD.redPoint:getStateByKey(Constant.FUNC_TYPE_PACK_PRESTIGE) )
end

function ClassRef:refreshPlayerRedPoint()
	self._playerPanel:refreshRedPonit()
end

function ClassRef:refreshClothesRedPoint()
	local panel = self._panelTable[3]
	if panel then
		panel:refreshRedPoint()
	end
end

return ClassRef
